import config from '../config'

let fns = {}

/**
 * 
 * 获取积分排名
 */
fns.getScoreRankNumber = (params, success, fail) => {
  dd.showLoading();

  dd.httpRequest({

    url: config.domain + '/user/integral/list',
    headers: {
      "Content-Type": "application/json"
    },
    method: 'POST',
    dataType: 'json',
    data: JSON.stringify(params),

    success: (res) => {
      dd.hideLoading();
      if (res.data.code == 0) {
        success && success(res)
      } else {
        fail && fail(res.data.message)
      }
    },

    fail: () => {
      dd.hideLoading();
      fail && fail('网络异常')
    }

  });
}

/**
 * 
 * 获取琅琊榜排名
 */
fns.getLangYaRank = (params, success, fail) => {
  dd.showLoading();

  dd.httpRequest({

    url: config.domain + '/ranking/page',
    headers: {
      "Content-Type": "application/json"
    },
    method: 'POST',
    dataType: 'json',
    data: JSON.stringify(params),

    success: (res) => {
      dd.hideLoading();
      if (res.data.code == 0) {
        success && success(res)
      } else {
        fail && fail(res.data.message)
      }
    },

    fail: () => {
      dd.hideLoading();
      fail && fail('网络异常')
    }

  });
}


/**
 * 
 * 获取用户打榜列表
 */
fns.userRankList = (params, success, fail) => {
  dd.showLoading();

  dd.httpRequest({

    url: config.domain + '/ranking/list',
    headers: {
      "Content-Type": "application/json"
    },
    method: 'POST',
    dataType: 'json',
    data: JSON.stringify(params),

    success: (res) => {
      dd.hideLoading();
      if (res.data.code == 0) {
        success && success(res)
      } else {
        fail && fail(res.data.message)
      }
    },

    fail: () => {
      dd.hideLoading();
      fail && fail('网络异常')
    }

  });
}
/**
 * 
 * 删除用户打榜信息
 */
fns.deleteUserRank = (params, success, fail) => {
  dd.showLoading();

  dd.httpRequest({
    url: config.domain + '/ranking/delete',
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    },
    method: 'POST',
    dataType: 'json',
    data: params,

    success: (res) => {
      dd.hideLoading();
      if (res.data.code == 0) {
        success && success(res)
      } else {
        fail && fail(res.data.message)
      }
    },

    fail: () => {
      dd.hideLoading();
      fail && fail('网络异常')
    }

  });
}
/**
 * 
 * 添加打榜信息
 */
fns.addUserRank = (params, success, fail) => {
  dd.showLoading();

  dd.httpRequest({

    url: config.domain + '/ranking/add',
    headers: {
      "Content-Type": "application/json"
    },
    method: 'POST',
    dataType: 'json',
    data: JSON.stringify(params),

    success: (res) => {
      dd.hideLoading();
      if (res.data.code == 0) {
        success && success(res)
      } else {
        fail && fail(res.data.message)
      }
    },

    fail: () => {
      dd.hideLoading();
      fail && fail('网络异常')
    }

  });
}

/**
 * 
 * 添加PK信息
 */
fns.addPK = (params, success, fail) => {
  dd.showLoading();

  dd.httpRequest({

    url: config.domain + '/pk/add',
    headers: {
      "Content-Type": "application/json"
    },
    method: 'POST',
    dataType: 'json',
    data: JSON.stringify(params),

    success: (res) => {
      dd.hideLoading();
      if (res.data.code == 0) {
        success && success(res)
      } else {
        fail && fail(res.data.message)
      }
    },

    fail: () => {
      dd.hideLoading();
      fail && fail('网络异常')
    }

  });
}



module.exports = fns